

##Input:
##        > raw/shp/landtagwahl2018_stimmbezirke.shp [shapefile with precinct delineation of 2018]
##        > raw/RWI/GEO_RED_v3/Raster_shp/ger_1km_rectangle.shp [shapefile with INSPIRE 1km ID]
##
##Output: tmp/precinct_raster_inter_area.shp
##
##Task: Project and intersect both shapefiles
 


# Import the system modules
import numpy as np
import arcpy
import os
import csv
from arcpy import env
arcpy.env.overwriteOutput = True

import arcgisscripting
gp = arcgisscripting.create()
gp.toolbox = "management"

# Include extensions
arcpy.CheckOutExtension("spatial")

# Projected coordinate system
outCS = arcpy.SpatialReference('WGS 1984 UTM Zone 32N') 
# Set workspace
project = ""
env.workspace = project + "02_rawdata/RWI/02_data/"

# pull and project precinct shp
precinct            = "raw/shp/landtagwahl2018_stimmbezirke.shp"
precinct_proj       = "tmp/precinct_proj.shp"
arcpy.Project_management(precinct, precinct_proj,outCS)

# pull and project raster shp
raster = "raw/RWI/GEO_RED_v3/Raster_shp/ger_1km_rectangle.shp"
raster_proj       = "tmp/raster_proj.shp"
arcpy.Project_management(raster, raster_proj,outCS)

# intersect precinct with raster
precint_raster_inter = "tmp/precinct_raster_inter.shp"
arcpy.Intersect_analysis([precinct_proj,raster_proj], precint_raster_inter)

# calculate areas of intersected shp
calculate_output = "tmp/precinct_raster_inter_area.shp"
arcpy.CalculateAreas_stats(precint_raster_inter, calculate_output)

print "finish"
